package pl.edu.agh.ssm.monitor.visualization;

import java.awt.geom.Rectangle2D;
import java.util.Iterator;

import prefuse.action.layout.Layout;
import prefuse.visual.DecoratorItem;
import prefuse.visual.VisualItem;

/**
 * 
 * @author Monika Nawrot
 * 
 */
public class EdgeLabelLayout extends Layout {

	public EdgeLabelLayout(String group) {
		super(group);
	}

	@SuppressWarnings("unchecked")
	public void run(double frac) {
		Iterator iter = m_vis.items(m_group);
		while (iter.hasNext()) {
			DecoratorItem decorator = (DecoratorItem) iter.next();

			if (!decorator.isValid()) {
				continue;
			}

			VisualItem decoratedItem = decorator.getDecoratedItem();

			try {
				Rectangle2D bounds = decoratedItem.getBounds();

				double x = bounds.getCenterX();
				double y = bounds.getCenterY();

				setX(decorator, null, x);
				setY(decorator, null, y);
			} catch (IllegalStateException ex) {

			}
		}
	}
}
